/**
 * Copyright (c) 2009 Teoti Graphix, LLC See:
 *     http://tkarchitecture.teotigraphix.org
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 * 
 * @author Michael Schmalle mschmalle@teotigraphix.com
 */
package test.suite.tkaframework.support.layer
{

import flash.events.Event;
import flash.events.IEventDispatcher;

import mx.core.IVisualElement;

import org.teotigraphix.dx.interfaces.IComponentLayerClient;
import org.teotigraphix.dx.patterns.layer.ComponentLayer;

public class TestComponentLayer extends ComponentLayer
{
	public var activateFlag:Boolean = false;
	public var deactivateFlag:Boolean = false;
	public var commitComponentFlag:Boolean = false;
	
	// holds TestToolKitClient
	public function TestComponentLayer()
	{
		super();
	}
	
	override public function activate(host:IEventDispatcher):void
	{
		super.activate(host);
		activateFlag = true;
	}
	
	override public function deactivate(host:IEventDispatcher):void
	{
		super.deactivate(host);
		deactivateFlag = true;
	}	
	
	override protected function commitComponent():void
	{
		super.commitComponent();
		commitComponentFlag = true;
	}
	
	
	//--------------------------------------------------------------------------
	//
	//  IBehaviorLayer API :: Methods
	//
	//--------------------------------------------------------------------------
	
	public function registerClient(api:Class, client:IComponentLayerClient):void
	{
		super.registerProxy(api, client);
	}
	
	public function removeClient(api:Class):IComponentLayerClient
	{
		return super.removeProxy(api) as IComponentLayerClient;
	}
	
	public function hasClient(api:Class):Boolean
	{
		return super.hasProxy(api);;
	}
	
	public function getClient(api:Class):IComponentLayerClient
	{
		return super.getProxy(api) as IComponentLayerClient;
	}
	
	public function getClients():Array
	{
		var proxies:Array = [];
		var items:Array = getAllProxies();
		var len:int = items.length;
		for (var i:int = 0; i < len; i++)
		{
			proxies.push(items[i]);
		}
		return proxies;
	}
	
	override protected function createLayerEvent(
		type:String, load:Boolean = false):Event
	{
		return new TestComponentLayerEvent(type);
	}	
	
	override protected function dispatchAddEvent(api:Class, proxy:IComponentLayerClient):void
	{
		var e:TestComponentLayerEvent = 
			createLayerEvent(TestComponentLayerEvent.CLIENT_ADD) as TestComponentLayerEvent;
		
		e.api = api;
		e.client = proxy as IComponentLayerClient;
		e.component = component;
		
		dispatchEvent(e);
		
		if (component)
			component.dispatchEvent(e);
	}
	
	override protected function dispatchRemoveEvent(api:Class, proxy:IComponentLayerClient):void
	{
		var e:TestComponentLayerEvent = 
			createLayerEvent(TestComponentLayerEvent.CLIENT_REMOVE) as TestComponentLayerEvent;
		
		e.api = api;
		e.client = proxy as IComponentLayerClient;
		e.component = component;
		
		dispatchEvent(e);
		
		if (component)
			component.dispatchEvent(e);
	}	
}
}